<template>
	<view class="addUser">
		<view class="head">
			<uni-icons type="back" size="30" color="#454545" class="icon_back" @click="navigBack"></uni-icons>
		</view>

		<view class="body">
			<view class="form">
				<text>添加用户</text>
				<view class="input">
					<input class="i_put" type="number" v-model="account" maxlength="11" placeholder="请输入你的轩聊号"
						@input="AccountInput" />
				</view>
				<view class="input">
					<input class="i_put" :type="pwdType" v-model="pwd" maxlength="15" placeholder="请输入密码"
						@input="handleInput" />
					<uni-icons type="eye-slash" size="25" v-show="!seeing" class="icon"
						@click="updatePwdType"></uni-icons>
					<uni-icons type="eye" size="25" v-show="seeing" class="icon" @click="updatePwdType"></uni-icons>
				</view>
			</view>
			<view class="buom" @click="mylogin">
				<view class="back"></view>
				<text>登录</text>
			</view>
		</view>

		<view class="botom">
			<view @click="NavigatorPwd">忘记密码</view>
			<view @click="NavigatorRegister">新用户注册</view>
			<view>扫码登录</view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations,
	} from 'vuex'
	import { login } from '../../common/api';
	export default {
		data() {
			return {
				seeing: false,
				pwdType: 'password',
				account: '',
				pwd: '',
			};
		},
		methods: {
			...mapMutations('info', ['CreateMyInfo']),
			navigBack() {
				uni.navigateBack();
			},
			NavigatorRegister(){
				uni.navigateTo({
					url: '/subpkg/register/register'
				})
			},
			NavigatorPwd(){
				uni.navigateTo({
					url: '/subpkg/setPwd/setPwd'
				})
			},
			updatePwdType() {
				this.seeing = !this.seeing;
				this.pwdType = (this.pwdType == 'password') ? 'text' : 'password';
			},
			handleInput(event) {
				const value = event.detail.value.replace(/[\u4e00-\u9fa5]/g, '');
				this.pwd = value;
			},
			AccountInput(e) {
				
			},
			mylogin() {
				if (this.account.length < 11) {
					uni.showToast({
						title: '账号不足11位',
						duration: 1000,
						icon: 'error'
					});
					return;
				}
				login({
					account: this.account,
					password: this.pwd
				}).then((res) => {
					let resData = res.data;
					if (res.code == 200) {
						uni.setStorageSync('token', res.token);
						this.CreateMyInfo(resData);
						setTimeout(() => {
							uni.showToast({
								title: '登录成功',
								duration: 2000
							})
							uni.navigateTo({
								url: '/subpkg/setup/setup'
							})
						}, 2000);
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.addUser {
		.head {
			width: 750rpx;
			height: 100rpx;
			padding: 50rpx 30rpx;

			.icon_back {
				background-color: #dddddd;
				border-radius: 50rpx;
				padding: 10rpx;
			}
		}

		.body {
			width: 750rpx;
			height: 400rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.form {
				height: 200rpx;

				text {
					font-size: 38rpx;
					font-weight: bold;
					color: #4c4c4c;
				}

				.input {
					width: 500rpx;
					height: 100rpx;
					border-bottom: 1rpx solid #797979;
					display: flex;
					align-items: center;
					.i_put{
						width: 450rpx;
						height: 100rpx;
						font-size: 32rpx;
						padding: 10rpx;
					}
				}
			}

			.buom {
				margin-top: 100rpx;
				width: 300rpx;
				height: 80rpx;
				border: 1rpx solid lightseagreen;
				display: flex;
				justify-content: center;
				align-items: center;
				overflow: hidden;
				position: fixed;
				top: 400rpx;
				font-weight: bold;
				font-size: 32rpx;
				border-radius: 10rpx;

				&:active {
					transform: scale(0.9);
				}

				text {
					position: fixed;
				}

				.back {
					border: 1rpx solid rebeccapurple;
					position: absolute;
					width: 600rpx;
					height: 200rpx;
					background: linear-gradient(90deg, rgba(65, 254, 179, 1) 0%, rgba(38, 238, 244, 1) 50%, rgba(14, 130, 246, 1) 100%);

					animation: move 8s infinite linear alternate;

					@keyframes move {
						from {
							transform: translateX(100rpx);
						}

						to {
							transform: translateX(-100rpx);
						}
					}
				}
			}
		}

		.botom {
			position: fixed;
			bottom: 50rpx;
			left: 0;
			right: 0;
			display: flex;
			justify-content: space-around;
			font-size: 25rpx;

			:active {
				transform: scale(0.9);
				transition: transform 0.1s;
			}
		}
	}
</style>